package com.lanp.native_test.ExecutorsRun.CustomTheadExecutor;

import org.apache.commons.lang3.RandomStringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author jiangpeng
 * Created with IntelliJ IDEA.
 * Description:  实现优先级
 * Date: 2022-07-27 18:38:58
 */
public class TestRunnable implements Runnable, Comparable<TestRunnable> {

    private int sort;

    public TestRunnable(int sort) {
        this.sort = sort;
    }

    @Override
    public int compareTo(TestRunnable o) {
        if (this.sort > o.sort) {
            return -1;
        } else if (this.sort == o.sort) {
            return 0;
        } else {
            return 1;
        }
    }

    @Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        Date nowDate = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(nowDate) + "   " + this.sort + "-索引:" + RandomStringUtils.randomAlphabetic(10));
    }
}
